package cn.codeforfun.service;

import cn.codeforfun.dao.UserDao;
import cn.codeforfun.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * Created by Administrator on 2017/2/25.
 */
@Service
@Transactional
public class UserService {

    @Autowired
    private UserDao userDao;


    @CachePut(value = "userById", key = "'id:'+#user.id")
    public User save(User user) {
        User save = userDao.save(user);
        return save;
    }

    @Cacheable(value = "userById", key = "'id:'+#p0")
    public User findOne(Long id) {
        return userDao.findOne(id);
    }

    @CacheEvict(value = "userById", key = "'id:'+#p0")
    public void delete(Long id) {
        userDao.delete(id);
    }


}